package site;

import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;

import androidx.appcompat.app.AppCompatActivity;

import com.example.sports_meet.R;

import dateBase.Judge_Site_DBHelper;
import util.ToastUtil;

public class Site_update extends AppCompatActivity {
    private EditText editGName, editGContent;
    private Spinner spinner;
    private Button btnSub;
    private Judge_Site_DBHelper mHelper;
    private String name, type, newData;
    private int position;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_site_update);
        init();
        spinnerinit();
    }


    public void init() {
        editGName = (EditText) findViewById(R.id.editgname);
        editGContent = (EditText) findViewById(R.id.editgcontent);
        btnSub = (Button) findViewById(R.id.btnsub);
        btnSub.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                name = editGName.getText().toString();
                newData = editGContent.getText().toString();

                position = spinner.getSelectedItemPosition();
                type = spinner.getSelectedItem().toString();
                if (mHelper.s_update(type, newData, name) > 0) {
                    ToastUtil.show(Site_update.this, "更新成功");
                } else {
                    ToastUtil.show(Site_update.this, "更新失败");
                }
            }
        });
    }

    public void spinnerinit() {
        spinner = (Spinner) findViewById(R.id.spinner3);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
                R.array.site, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);

    }


    @Override
    protected void onStart() {
        super.onStart();
        mHelper = Judge_Site_DBHelper.getInstance(this);
        //打开读写链接
        mHelper.openReadLink();
        mHelper.openWriteLink();
        //获得帮助器实例
    }

    @Override
    protected void onStop() {
        super.onStop();
        mHelper.closeLink();
    }
}
